home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_enlightenment.idb / usr / freeware / bin / e_gen_gnome_menu.z / e_gen_gnome_menu
Text File  |  2001-10-09  |  7KB  |  293 lines

  1. #!/bin/sh
  2. ###############################################################################
  3. # generates a file.menu format for Enlightenment out of a GNOME menu hierarchy#
  4. #
  5. # Copyright (C) 1999 Carsten Haitzler, Geoff Harrison  and various contributors
  6. # Permission is hereby granted, free of charge, to any person obtaining a copy
  7. # of this software and associated documentation files (the "Software"), to
  8. # deal in the Software without restriction, including without limitation the
  9. # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  10. # sell copies of the Software, and to permit persons to whom the Software is
  11. # furnished to do so, subject to the following conditions:
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies of the Software, its documentation and marketing & publicity
  14. # materials, and acknowledgment shall be given in the documentation, materials
  15. # and software packages that this Software was used.
  16. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. # THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20. # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. ###############################################################################
  23.  
  24. # if we dont have enough arguments
  25. if [ $# -lt 3 ]; then
  26.   echo "usage:"
  27.   echo "    "$0" base_name output_dir output_file.menu [gnome_app_base_dir]"
  28.   exit
  29. fi
  30.  
  31. # setup variables
  32. BASE="$1"
  33. ODIR="$2"
  34. OUT="$3"
  35.  
  36. CONVERT_CMD="`which convert`"
  37.  
  38. # NEW
  39. find_app_base_dir() {
  40.   ADIR="`gnome-config --prefix`/share/gnome/apps"
  41.   if [ ! -d "$ADIR" ]; then
  42.     ADIR="/usr/share/gnome/apps"
  43.   else
  44.     return
  45.   fi
  46.   if [ ! -d "$ADIR" ]; then
  47.     ADIR="/usr/share/apps"
  48.   else
  49.     return
  50.   fi
  51.   if [ ! -d "$ADIR" ]; then
  52.     ADIR="/usr/local/share/apps"
  53.   else
  54.     return
  55.   fi
  56.   if [ ! -d "$ADIR" ]; then
  57.     ADIR="/usr/gnome/share/apps"
  58.   else
  59.     return
  60.   fi
  61.   if [ ! -d "$ADIR" ]; then
  62.     ADIR="/usr/local/gnome/share/apps"
  63.   else
  64.     return
  65.   fi
  66.   if [ ! -d "$ADIR" ]; then
  67.     ADIR="/opt/gnome/share/apps"
  68.   else
  69.     return
  70.   fi
  71.   if [ ! -d "$ADIR" ]; then
  72.     ADIR="/opt/gnome/share/gnome/apps"
  73.   else
  74.     return
  75.   fi
  76.   if [ ! -d "$ADIR" ]; then
  77.     ADIR="/usr/X11R6/share/gnome/apps"
  78.   else
  79.     return
  80.   fi
  81.   if [ ! -d "$ADIR" ]; then
  82.     ADIR="/opt/local/share/apps"
  83.   else
  84.     return
  85.   fi
  86. }
  87.  
  88. find_icon_base_dir() {
  89.   IDIR="`gnome-config --prefix`/share/pixmaps"
  90.   if [ ! -f "${IDIR}/gnome-help.png" ]; then
  91.     IDIR="/usr/share/pixmaps"
  92.   else
  93.     return
  94.   fi
  95.   if [ ! -f "${IDIR}/gnome-help.png" ]; then
  96.     IDIR="/usr/share/gnome/pixmaps"
  97.   else
  98.     return
  99.   fi
  100.   if [ ! -f "${IDIR}/gnome-help.png" ]; then
  101.     IDIR="/usr/local/share/pixmaps"
  102.   else
  103.     return
  104.   fi
  105.   if [ ! -f "${IDIR}/gnome-help.png" ]; then
  106.     IDIR="/usr/gnome/share/pixmaps"
  107.   else
  108.     return
  109.   fi
  110.   if [ ! -f "${IDIR}/gnome-help.png" ]; then
  111.     IDIR="/usr/local/gnome/share/pixmaps"
  112.   else
  113.     return
  114.   fi
  115.   if [ ! -f "${IDIR}/gnome-help.png" ]; then
  116.     IDIR="/opt/gnome/share/pixmaps"
  117.   else
  118.     return
  119.   fi
  120.   if [ ! -f "${IDIR}/gnome-help.png" ]; then
  121.     IDIR="/opt/gnome/share/gnome/pixmaps"
  122.   else
  123.     return
  124.   fi
  125.   if [ ! -f "${IDIR}/gnome-help.png" ]; then
  126.     IDIR="/usr/X11R6/share/gnome/pixmaps"
  127.   else
  128.     return
  129.   fi
  130.   if [ ! -f "${IDIR}/gnome-help.png" ]; then
  131.     IDIR="/opt/local/share/pixmaps"
  132.   else
  133.     return
  134.   fi
  135. }
  136.  
  137. if [ $# -eq 4 ]; then
  138.   DIR="$4"
  139. else
  140.    find_app_base_dir
  141.    DIR="$ADIR"
  142. fi
  143.  
  144. # In most cases I believe the icons can be found in the directory that is
  145. # ../../pixmaps from $ADIR.
  146. find_icon_base_dir
  147. GICONDIR="$IDIR"
  148.  
  149. # if the apps dir doesn't exist in the end then exit
  150. if [ ! -d "$DIR" ]; then
  151.   exit
  152. fi
  153. # if the destination dir doesnt exist - create it
  154. if [ ! -d "$ODIR" ]; then
  155.   mkdir "$ODIR"
  156. fi
  157.  
  158. # function to check its a GNOME desktop file 
  159. is_desktop() {
  160.   VAL="`grep "\[Desktop Entry\]" $1`"
  161.   if [ -n "$VAL" ]; then
  162.     IS_DESKTOP_RESULT="`awk -F= 'BEGIN { n="" } END { printf("%s", n) } $1 ~ "^Name\\\['$LANG'\\\]" {n=$2;exit} $1 ~ "^Name$" {n=$2}' $1`"
  163.     if [ -n "$IS_DESKTOP_RESULT" ]; then
  164.       return 0
  165.     fi
  166.   fi
  167.   IS_DESKTOP_RESULT=""
  168.   return 1
  169. }
  170.  
  171. # function to get the sortorder list -if there is one
  172. get_sortorder() {
  173.   if [ -f "${1}/.order" ]; then
  174.     VAL="`awk '{printf("%s ", $1);}' $1"/.order" | sed 's/,/ /g'`"
  175.   else
  176.     VAL=""
  177.   fi
  178.   GET_SORT_ORDER_RESULT="$VAL"
  179.   for I in `/bin/ls "$1"`; do
  180.     IS_IN="n"
  181.     for J in $VAL; do
  182.       if [ "$J" = "$I" ]; then
  183.         IS_IN="y"
  184.     continue 2
  185.       fi
  186.     done
  187.     GET_SORT_ORDER_RESULT="${GET_SORT_ORDER_RESULT}${I} "
  188.   done
  189.   return 0
  190. }
  191.  
  192. get_icon() {
  193.   VAL2="`awk -F= '$1 ~ "^Icon$" {printf("%s", $2); exit;}' $1`"
  194.   if [ -z "$VAL2" ]; then
  195.     GET_ICON_RETURN=""
  196.     return 1
  197.   fi
  198.  
  199.   # If we have "convert" and the icon havsn't already been scaled down, scale
  200.   # it down now!
  201.  
  202.   GET_ICON_RETURNDIR="${ODIR}/gnome_icons"
  203.   if [ ! -d "$GET_ICON_RETURNDIR" ];then
  204.     mkdir "$GET_ICON_RETURNDIR"
  205.   fi
  206.  
  207.   # The "Icon" entery can contain an absolute path, if it does forget the
  208.   # $GICONDIR
  209.   VAL3="`echo $VAL2 | grep /`"
  210.   if [ "$VAL3" != "$VAL2" ];then
  211.     if [ -n "$VAL2" ]; then
  212.     GICON="$GICONDIR/$VAL2"
  213.     GET_ICON_RETURN="$GET_ICON_RETURNDIR/$VAL2"
  214.     fi
  215.   else
  216.     if [ -n "$VAL3" ]; then
  217.     GICON="$VAL3"
  218.     GET_ICON_RETURN="$GET_ICON_RETURNDIR/`basename "$VAL3"`"
  219.     fi
  220.   fi
  221.   if [ -n "$CONVERT_CMD" -a -n "$GICON" -a -f "$GICON" -a ! \
  222.         -f "$GET_ICON_RETURN" ]; then
  223.     "$CONVERT_CMD" "$GICON" -geometry 16x16 "$GET_ICON_RETURN"
  224.   fi
  225.   
  226.   return 0
  227. }
  228.  
  229. get_exec() {
  230.   GET_EXEC_RETURN="`awk -F= '$1 ~ "^Exec$" {printf("%s", $2);}' $1`"
  231.   if [ -z "$GET_EXEC_RETURN" ]; then
  232.     GET_EXEC_RETURN=""
  233.     return 1
  234.   fi
  235.   return 0
  236. }
  237.  
  238. E_TITLE="GNOME Menu"
  239.  
  240. ORDER=""
  241. # if a .directory file exists - read it
  242. F=$DIR"/.directory"
  243. if [ -f $F ]; then
  244.   is_desktop $F
  245.   NAME="$IS_DESKTOP_RESULT"
  246.   if [ -n "$NAME" ]; then
  247.     E_TITLE="$NAME"
  248.   fi
  249. fi
  250. get_sortorder "$DIR"
  251. ORDER="$GET_SORT_ORDER_RESULT"
  252.  
  253. # print the menu title
  254. echo \"$E_TITLE\" > $OUT
  255.  
  256. # for every subdir in the dir list or order - print it
  257. for F in $ORDER; do
  258.   FF="${DIR}/${F}"
  259.   if [ -d "$FF" ]; then
  260.     FFF="${FF}/.directory"
  261.     if [ -f "$FFF" ]; then
  262.       is_desktop "$FFF"
  263.       NAME="$IS_DESKTOP_RESULT"
  264.     else
  265.       NAME="`echo $F | sed 's/_/ /g'`"
  266.     fi
  267.     FFF="${ODIR}/${BASE}"
  268.     if [ ! -d "$FFF" ]; then
  269.       mkdir "$FFF"
  270.     fi
  271.     MFILE="${FFF}/${F}.menu"
  272.     "$0" "${BASE}/${F}" "$ODIR" "$MFILE" "${DIR}/${F}"
  273.     get_icon "${FF}/.directory"
  274.     ICO="$GET_ICON_RETURN"
  275.     echo "\"$NAME\" \"$ICO\" menu \"$MFILE\"" >> $OUT
  276.   else
  277.     if [ -r "$FF" ]; then
  278.       is_desktop $FF
  279.       NAME="$IS_DESKTOP_RESULT"
  280.       if [ -n "$NAME" ]; then
  281.     get_exec "$FF"
  282.     EXE="$GET_EXEC_RETURN"
  283.         get_icon "$FF"
  284.         ICO="$GET_ICON_RETURN"
  285.     echo "\"$NAME\" \"$ICO\" exec \"$EXE\"" >> $OUT
  286.       fi
  287.     fi
  288.   fi
  289. done
  290.